import { registerI18nMessages } from '@mxpio/locales';

export async function getMessages() {
  const modules = import.meta.glob('./lang/*.ts', { eager: true });
  const messages = Object.entries(modules).reduce(
    (acc, [path, mod]: [string, any]) => {
      const lang = path.split('/').pop()?.replace('.ts', '');
      if (lang) acc[lang] = mod.default?.message;
      return acc;
    },
    {} as Record<string, any>,
  );
  return messages;
}

export async function setupI18n() {
  const messages = await getMessages();
  registerI18nMessages(messages);
}
